<template>
  <el-dialog v-model="state.visible" title="注销账户" width="30%">
    <span>注销后，所有信息均将被删除，且无法恢复，是否注销？</span>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="state.visible = false">取 消</el-button>
        <el-button type="primary" @click="confirmCancel">确 定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import { defineComponent } from "vue";
import { deleteUser } from "@/api/axios/admin"
import { CODE_KEY, CODE_SUCCESS } from "@/api/params"
import { ElMessage } from "element-plus"
import { useStore } from "vuex"

export default defineComponent({
  
  props: {
    state: {
      visible: Boolean,
    },
    parentState: {
      visible: Boolean
    }
  },
  setup (props) {
    
    const store = useStore();
    
    const confirmCancel = () => {
      deleteUser().then(res => {
        if(res && res.data[CODE_KEY] === CODE_SUCCESS) {
          // 弹出信息
          ElMessage.success("删除成功");
          // 关闭所有对话框
          props.state.visible = false;
          props.parentState.visible = false;
          
          // 清除信息
          store.commit("logout");
        }
      })
    }
    
   return {
     confirmCancel
   }
  }
})
</script>

<style>
</style>
